

window.onload = function () {



    // console.log(ospan)
    var odiv = document.querySelector(".time");
    var ospan = odiv.children;
    function daojishi() {
        var nowdate = new Date();

        var h = nowdate.getHours();
        var h1 = h + 1;
        var hour = document.querySelector(".hours");
        hour.innerHTML = h1 + ":00";
        var m = nowdate.getMinutes();
        var s = nowdate.getSeconds();

        var m1 = 60 - m;
        var s1 = 60 - s;


        m1 = m1 < 10 ? "0" + m1 : m1;
        s1 = s1 < 10 ? "0" + s1 : s1;

        if (m1 <= 59) {
            ospan[0].innerText = "00";
        } else {
            ospan[0].innerText = "01";
        }
        ospan[2].innerText = m1;
        ospan[4].innerText = s1;

    }

    var timer = setInterval(function () {
        daojishi();
    }, 1000)


    $(window).scroll(function () {
        let st = $(this).scrollTop();
        if (st > 800) {
            $(".sea-hd-warp").css({ "display": "block" });
        } else {
            $(".sea-hd-warp").css({ "display": "none" });
        };
    })

    //获取用户ID
    function getID() {
        let uid = localStorage.getItem('uid');
        console.log(uid);
        if (uid) {
            $("#nav-right li:eq(0) a:eq(0)").text(uid);
            $(".hdmas p").empty().text(uid);
        }
    }
    getID();

    function bannerswitch() {
        let url = 'http://jx.xuzhixiang.top/ap/api/allproductlist.php'

        axios.get(url, {
            params: {
                uid: 44883
            }
        }).then(res => {
            let arr = res.data.data;
            let html = '';
            for (let i = 4; i < 7; i++) {
                html += `
            <figure>
                <img src="
                ${arr[i].pimg}" alt="">
                <figcaption><a href="item.html?id=${arr[i].pid}">${arr[i].pname}</a></figcaption>
            </figure>
            `
            }
            let list = document.querySelector(".top-bot");
            list.innerHTML = html;
        })
    }
    bannerswitch();


    function loadData() {
        let url = 'http://jx.xuzhixiang.top/ap/api/allproductlist.php'

        axios.get(url, {
            params: {
                uid: 44883
            }
        }).then(res => {
            console.log(res.data.data);
            // 商品数组
            let arr = res.data.data;
            let html = '';
            for (let i = 0; i < 4; i++) {
                html += `<figure>
                <img src="${arr[i].pimg}" alt="">
                <figcaption>
                <a href="item.html?id=${arr[i].pid}"><h6>${arr[i].pname}</h6></a>
                <b>￥${arr[i].pprice}</b>
                <span>￥${arr[i].pprice}</span>
                </figcaption>
                </figure>`
            }

            let list = document.querySelector('.salecon-right')
            list.innerHTML = html;

            let html1 = '';
            html1 += `<a href="item.html?id=${arr[0].pid}"> <img src="${arr[0].pimg}" alt=""></a>`
            let list1 = document.querySelector(".banner-swi ");
            let list2 = list1.children;
            for (let i = 0; i < list2.length; i++) {
                list2[i].innerHTML = html1
            }
            let html2 = '';
            for(let i = 0;i<15;i++){
               html2+=` <a href="item.html?id=${arr[i].pid}">
               <img src="${arr[i].pimg}" alt="">
               <p><span>自营</span>${arr[i].pname}</p>
               <b>￥${arr[i].pprice}</b>
           </a>` 
            }
            let list3 = document.querySelector(".morelist");
            list3.innerHTML= html2;

        })
    }
    loadData();
};

// $(function(){
//     $(window).scroll(function(){
//         let st = $(this).scrollTop();
//         if(st>500){
//             $(".ele").css({"position":"fixed","right":"0","top":"53px"})
//         }
//         $("#in-con div").each(function(){
//             if(st>=$(this).offset().top){
//                 let index = $(this).index();
//                 $("#in-con div").eq(index).addClass("hover").siblings().removeClass("hover");
//             }
//         })
//     })

//     $(".ele div").click(function(){
//         let index = $(this).index();
//         $("body,html").stop().animate({
//             "scrollTop": $("#content li").eq(index).offset().top
//         }, 800, function () {
//             flag = true;
//         });

//         $(this).addClass("hover").siblings().removeClass("hover");


//     })
//     $("#floorNav li:last").click(function () {
//         flag = false;
//         $("body,html").stop().animate({
//             "scrollTop": 0
//         }, 800, function () {
//             flag = true;
//         });

//         $("#floorNav").fadeOut();

//     })
// })



